package com.boot.main.controller;

import com.boot.main.entity.ScomAd;
import com.boot.main.entity.ScomProduct;
import com.boot.main.service.IAdService;
import com.boot.main.service.IProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/v1/api")
@Api(tags = "产品管理")
public class ProductController {
    @Resource
    private IProductService productService;

    @RequestMapping(value="/products", method = RequestMethod.GET)
    @ApiOperation(value="获取产品列表")
    public Object getProducts(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit, @RequestParam("name") String name, @RequestParam("cid") Long cid, @RequestParam("shop_id") Long shop_id){
        return productService.getProducts(page, limit, name, cid, shop_id);
    }

    @RequestMapping(value="/product/{pid}", method = RequestMethod.GET)
    @ApiOperation(value="获取产品根据产品编码")
    public Object getProductByNum(@PathVariable("pid") String pid){
        return productService.getProductByNum(pid);
    }

    @RequestMapping(value="/product", method = RequestMethod.POST)
    @ApiOperation(value="新增产品")
    public Object saveProduct(@RequestBody ScomProduct product){
        return productService.saveProduct(product);
    }

    @RequestMapping(value="/product/{id}", method = RequestMethod.PUT)
    @ApiOperation(value="修改产品")
    public Object updateProduct(@RequestBody ScomProduct product){
        return productService.updateProduct(product);
    }

    @RequestMapping(value="/product/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value="删除产品")
    public Object deleteProduct(@PathVariable Long id){
        return productService.deleteProduct(id);
    }
}
